package br.com.techfor.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;

import br.com.techfor.dao.GenericDAO;

/**
 * 
 * @author alex.amaral
 * 
 * @param <T>
 */

public class GenericDAOImpl<T> implements GenericDAO<T> {

	private Class<T> classe;
	private Session session;

	public GenericDAOImpl(Class<T> classe, Session session) {
		super();
		this.classe = classe;
		this.session = session;

	}

	@Override
	public void save(T bean) {
		this.session.save(bean);
	}

	@Override
	public void update(T bean) {
		this.session.update(bean);

	}

	@Override
	public void delete(T bean) {
		this.session.delete(bean);

	}

	@SuppressWarnings("unchecked")
	@Override
	public T getBean(Serializable codigo) {

		T bean = (T) this.session.get(this.classe, codigo);

		return bean;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<T> getBeans() {
		List<T> beans = this.session.createCriteria(this.classe).list();
		return beans;
	}

}
